package model;

public class CompositeExecutionSequence extends ExecutionSequence{
	
	private final ExecutionSequence firstExecutionSequence;
	private final ExecutionSequence secondExecutionSequence;
	
	public CompositeExecutionSequence(final ExecutionSequence firstExecutionSequence, final ExecutionSequence secondExecutionSequence) {
		this.firstExecutionSequence = firstExecutionSequence;
		this.secondExecutionSequence = secondExecutionSequence;
	}
	
	@Override
	public boolean isRealizable(final System system, final Marking marking) {
		boolean result = false;
		try {
			if(firstExecutionSequence.isRealizable(system, marking)){
				final Marking markingAfterFirstSequence = firstExecutionSequence.getMarkingAfterExecution(system, marking);
				result = secondExecutionSequence.isRealizable(system, markingAfterFirstSequence);
			}	
		} catch (final NotActivatedException e) {
			result = false;
		}
		return result;
	}

	@Override
	public Marking getMarkingAfterExecution(final System system, final Marking marking)
			throws NotActivatedException {
		return this.secondExecutionSequence.getMarkingAfterExecution(system, this.firstExecutionSequence.getMarkingAfterExecution(system, marking));
	}
}
